package com.lankystar.sos.dao.impl;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.lankystar.sos.dao.IStatusDao;
import com.lankystar.sos.model.AuthStatus;
import com.lankystar.sos.model.ResponseStatus;
import com.lankystar.sos.model.SosStatus;
import com.lankystar.sos.model.UserType;

@Repository
public class StatusDaoImpl implements IStatusDao{

	@Autowired
	private SessionFactory sf;
	
	public Session getSession(){
		System.out.println("类型状态session 开启！！！");
		return sf.getCurrentSession();
	}
	
/**
 * userType
 */
	@Override
	public void addUserType(UserType record) {
		getSession().save(record);
	}

	@Override
	public void deleteUserType(UserType record) {
		getSession().delete(record);
	}
	
	@Override
	public UserType selectUserTypeById(Integer userTypeId) {
		UserType userType = (UserType) getSession().get(UserType.class, userTypeId);
		return userType;
	}
/**
 * sos
 */
	@Override
	public void addSosStatus(SosStatus record) {
		getSession().save(record);
	}

	@Override
	public void deleteSosStatus(SosStatus record) {
		getSession().delete(record);
	}

	@Override
	public SosStatus selectSosStatusById(Integer sosStatusId) {
		SosStatus sosStatus = (SosStatus) getSession().get(SosStatus.class, sosStatusId);
		return sosStatus;
	}
	
	@Override
	public SosStatus selectSosStatusBysoskey(Integer soskey) {
		SosStatus sos = (SosStatus) getSession().createQuery("from SosStatus where soskey=?")
									.setInteger(0, soskey).uniqueResult();
		return sos;
	}
	
	@Override
	public Object[] selectSosStatusBysosId(Integer sosId) {
		String sql = "from SosOrder o join o.sosStatus s where o.sosId = ?";
		Object[] ob = (Object[]) getSession().createQuery(sql).setInteger(0, sosId).uniqueResult();
		return ob;
	}

/**
 * RespStatus
 */
	@Override
	public void addRespStatus(ResponseStatus record) {
		getSession().save(record);
	}

	@Override
	public void deleteRespStatus(ResponseStatus record) {
		getSession().delete(record);
	}
	
	@Override
	public ResponseStatus selectRespStatusById(Integer respStatusId) {
		ResponseStatus respStatus = (ResponseStatus) getSession().get(ResponseStatus.class, respStatusId);
		return respStatus;
	}
	
	@Override
	public ResponseStatus selectResponseStatusByrespkey(Integer respkey) {
		ResponseStatus resp = (ResponseStatus) getSession().createQuery("from ResponseStatus where respkey=?")
										  .setInteger(0, respkey).uniqueResult();
		return resp;
	}

/**
 * AuthStatus
 */
	@Override
	public void addAuthStatus(AuthStatus record) {
		getSession().save(record);
	}

	@Override
	public void deleteAuthStatus(AuthStatus record) {
		getSession().delete(record);
	}

	@Override
	public AuthStatus selectAuthStatusById(Integer authStatusId) {
		AuthStatus authStatus = (AuthStatus) getSession().get(AuthStatus.class, authStatusId);
		return authStatus;
	}

	@Override
	public AuthStatus selectAuthStatusByauthkey(Integer authkey) {
		AuthStatus auth = (AuthStatus) getSession().createQuery("from AuthStatus where authkey=?")
									  .setInteger(0, authkey).uniqueResult();
		return auth;
	}


}
